package com.common.app.dialog

import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentManager
import com.common.app.R
import com.common.app.databinding.DialogShareBinding
import com.common.app.utls.share.UMengShareUtils
import com.common.base.app.extras.dpDimenPx
import com.common.base.app.fragment.BaseDialogFragment
import com.common.base.utils.AppUtils
//import com.umeng.socialize.UMShareAPI
//import com.umeng.socialize.UMShareListener
//import com.umeng.socialize.bean.SHARE_MEDIA

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/10/10
 * <p>
 * 描述：分享弹框
 * <p>
 * 修订历史：
 */
class ShareDialog : BaseDialogFragment<DialogShareBinding>(){

    interface ShareType {
        companion object {
            const val SHARE_URL = 1
        }
    }

    private var mShareType = ShareType.SHARE_URL
    private var mUrl = ""
    private var mTitle = ""
    private var mDesc = ""
//    private var mShareListener: UMShareListener?= null

    override fun getViewBinding(): DialogShareBinding = DialogShareBinding.inflate(layoutInflater)

    override fun getSelfWidth(): Int = ViewGroup.LayoutParams.MATCH_PARENT

    override fun getSelfHeight(): Int = dpDimenPx(R.dimen.dp_186).toInt()

    override fun getStyle(): Int = STYLE_NORMAL

    override fun initView(view: View) {
        super.initView(view)
        setShowPosition()

//        val umShareAPI = UMShareAPI.get(context)
//        val isWxInstalled = umShareAPI.isInstall(activity, SHARE_MEDIA.WEIXIN)
//        val isQQInstalled = umShareAPI.isInstall(activity, SHARE_MEDIA.WEIXIN)
//        //umShareAPI.isInstall(activity, SHARE_MEDIA.QZONE) 判断不准
//        val isQZoneInstalled = AppUtils.isAppInstalled("com.qzone")
//
//        if(!isWxInstalled && !isQQInstalled && !isQZoneInstalled){
//            //微信 QQ QQ空间都没有安装
//            mViewBinding.tvPlatformEmpty.isVisible = true
//        }else{
//            if (isWxInstalled){
//                //如果有安装微信 显示微信和朋友圈选项
//                mViewBinding.tvWechat.isVisible = true
//                mViewBinding.tvMoment.isVisible = true
//            }
//
//            if (isQQInstalled){
//                //如果有安装QQ 显示QQ和QQ空间
//                mViewBinding.tvQzone.isVisible = true
//                mViewBinding.tvQQ.isVisible = true
//            }
//
//            if (isQZoneInstalled){
//                //如果有单独安装QQ空间 显示QQ空间
//                mViewBinding.tvQzone.isVisible = true
//            }
//        }

    }

    override fun initEvent() {
        super.initEvent()

        mViewBinding.apply {
            tvWechat.setOnClickListener {
//                share(SHARE_MEDIA.WEIXIN)
                dismiss()
            }
            tvMoment.setOnClickListener {
//                share(SHARE_MEDIA.WEIXIN_CIRCLE)
                dismiss()
            }
            tvQzone.setOnClickListener {
//                share(SHARE_MEDIA.QZONE)
                dismiss()
            }
            tvQQ.setOnClickListener {
//                share(SHARE_MEDIA.QQ)
                dismiss()
            }
            tvCancel.setOnClickListener {
                dismiss()
            }
        }
    }

//    fun setShareUrlData(url: String, title: String?, desc: String?, shareListener: UMShareListener?): ShareDialog{
//        mShareType = ShareType.SHARE_URL
//        mUrl = url
//        mTitle = title ?: AppUtils.getString(R.string.app_name)
//        mDesc = desc ?: AppUtils.getString(R.string.app_name)
//        mShareListener = shareListener
//        return this
//    }
//
//    fun share(platform: SHARE_MEDIA){
//        when(mShareType){
//            ShareType.SHARE_URL -> UMengShareUtils.shareUrl(activity, platform, mUrl, mTitle, mDesc, mShareListener)
//        }
//    }

    override fun show(manager: FragmentManager, tag: String?) {
        super.show(manager, "shareDialog")
    }
}